<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
error_reporting(0);
require_once './Config.php';
require_once './Tencent.php';
$callback = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; //回调url
$callback = $callback . "?yyy=eee";
OAuth::init($client_id, $client_secret);
session_start();
if (isset($_GET["code"])) {
//第一次获得
    print_r($_GET);
    $url = OAuth::getAccessToken($_GET["code"], $callback);
    //第二次活得
    $r = Http::request($url);
    parse_str($r, $out);
   // print_r($out);
    //  echo $out['access_token'];
   // echo $out["expires_in"];
    if ($out['access_token']) {
        $_SESSION['t_access_token'] = $out['access_token'];
        $_SESSION['t_refresh_token'] = $out['refresh_token'];
        $_SESSION['t_expire_in'] = $out["expires_in"];
        $_SESSION['t_code'] = $_GET["code"];
        $_SESSION['t_openid'] = $_GET["openid"];
        $_SESSION['t_openkey'] = $_GET["openkey"];
      //  print_r($_SESSION);
        //验证授权
        $r = OAuth::checkOAuthValid();
        if ($r) {
             header('Location: http://127.0.0.1/opentest/tqqdemo/callback.php' ); //刷新页面这里为处理相应api请求的操作
           // echo "asdasd";
        } else {
            exit('<h3>授权失败,请重试</h3>');
        }
    }


    exit;
}



Tencent::$debug = $debug;
$callback = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; //回调url
$callback = $callback . "?yyy=eee"; //
$res1 = OAuth::getAuthorizeURL($callback); //生成第一次授权请求的url地址
//echo $res1;
//exit;
// $r = Http::request($res1);
//   print_r($r);
header('Location: ' . $res1);
?>
